package com.code.monitor.resolve;

import com.code.monitor.utils.IOUtils;

import java.io.InputStream;
import java.nio.charset.Charset;

/**
 * @author ggh
 * @date 2023/5/8
 */
public class PageRenderReslover {

    public static String resource(String path) {
        InputStream asStream = PageRenderReslover.class.getClassLoader().getResourceAsStream(path);
        return IOUtils.readInputStream(asStream, Charset.defaultCharset());
    }

    public static byte[] staticResource(String path) {
        path = path.substring(1);
        InputStream asStream = PageRenderReslover.class.getClassLoader().getResourceAsStream(path);
        return IOUtils.readInputStreamToByte(asStream);
    }

    public static String htmlPage(String path) {
        path = "pages" + path;
        return resource(path);
    }

    public static String homePage() {
        return resource("pages/index.html");
    }

    public static void main(String[] args) {
        System.out.println(staticResource("/js/tabler.min.js"));
    }
}
